import Vue from 'vue'
import VueRouter from 'vue-router'
import recommend from '../views/recommend.vue'
import store from '@/store'


Vue.use(VueRouter)

const routes = [
  
  {
    path: '/',
    redirect:"/login"
  },
  {
    path: '/login',
    name: "login",
    meta:{
      headerflag:true
    },
    component:() => import('../components/base/login.vue')
  },
  {
    path: '/register',
    name: "register",
    
    component:() => import('../components/base/register.vue')
  },

  {
    path:"/userInfo",
    name:"userInfo",
    meta:{
      headerflag:true
    },
    component:() => import("../components/userInfo/index.vue"),
    // 独享路由守卫
    beforeEnter:(to,from,next)=>{
      let login = store.state.login;
      // 判断的登录情况
      if(!login){
        next("/login");
        return;
      }else{
        next();
      }
    }
  },

  {
    path:"/recommend",
    name:"recommend",
    component:recommend
  },
  {
    path: '/recommend/musiclist',
    meta:{
      headerflag:true
    },
    component:() => import('../components/recommend/musiclist.vue')
  },
  {
    path:"/singer",
    name:"singer",
    component:() => import('../views/singer.vue')
  },
  {
    path: '/recommend/singerDetail',
    meta:{
      headerflag:true
    },
    component:() => import('../components/recommend/singerDetail.vue')
  },
  {
    path:"/rank",
    name:"rank",
    component:() => import('../views/rank.vue')
  },
  {
    path:"/recommend/ranklist",
    meta:{
      headerflag:true
    },
    component:() => import('../components/recommend/ranklist.vue')
  },
  {
    path:"/recommend/search",
    meta:{
      headerflag:true
    },
    component:() => import('../components/recommend/search.vue')
  },
  {
    path:"/newMv",
    component:() => import('../views/newMv.vue')
  },
  {
    path:"/updata",
    name:"updata",
    meta:{
      headerflag:true
    },
    component:() => import("../components/userInfo/updata.vue"),
  },
  {
    
    path:"/recommend/mvDetails",
    name:"mvDetails",
    meta:{
      headerflag:true
    },
    component:() => import("../components/recommend/mvDetails"),
  },
  {
    path:"/radio",
    name:"radio",
    component:() => import('../views/radio.vue')
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
